/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package share;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mire
 */
public class Listener {

    protected int port;
    protected ServerSocket serverSocket;
    protected ExecutorService threadPool;
    protected boolean isStoped;

    public Listener(int port, ExecutorService threadPool) {
        this.port = port;
        this.threadPool = threadPool;
    }

    protected void openServerSocket() {
        try {
            serverSocket = new ServerSocket(port);
        } catch (IOException ex) {
            Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public synchronized boolean isStoped() {
        return this.isStoped;
    }

    public synchronized void stop() {
        isStoped = true;
        try {
            serverSocket.close();
        } catch (IOException ex) {
            Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
